<?php

namespace app\common\model\Subject;

use app\common\model\Business\Business;
use think\Model;

class Order extends Model
{
    // 表名
    protected $name = 'subject_order';
    // 忽略数据表不存在的字段
    protected $field = true;
    // 设置返回的结果类型
    protected $resultSetType = 'collection';
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = 'createtime';
    //禁止写入时间字段
    protected $updateTime = false;
    // 软删除的字段
    protected $deleteTime = 'deletetime';
    // 追加属性
    protected $append = [
        'subject',
        'createDate',
        'iscomment'
    ];
    public function getSubjectAttr($value,$data){
        return $this->hasOne('subject','id','subid')->find();
    }
    public function getCreateDateAttr($value,$data)
    {
        return date('Y-m-d H:i:s',$data['createtime']);
    }
    public function getIscommentAttr()
    {
        return true&&$this->hasOne('comment','orderid','id')->find();
    }
    public function subject()
    {
        return $this->belongsTo(Subject::class,'subid','id',[],'left')->setEagerlyType(0);
    }
    public function business()
    {
        return $this->belongsTo(Business::class,'busid','id',[],'left')->setEagerlyType(0);
    }
}
